﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Payton.WP7.Common.Interface;
using System.Collections.Generic;
using Payton.WP7.Common.Model;
using Payton.WP7.Common.Sina;
using Payton.WP7.Common.Tencent;
using Payton.WP7.Common.Renren;

namespace Payton.WP7.Common
{
    public abstract class MappingFactoryBase : IMappingFactory
    {
        public static IMappingFactory CreateFactory(SNSAccount account)
        {
            switch (account.ServiceProvider)
            {
                case SNSProviderType.Sina:
                    return new SinaMappingFactory(account);
                case SNSProviderType.Tencent:
                    return new TencentMappingFactory(account);
                case SNSProviderType.RenRen:
                    return new RenrenMappingFactory(account);
                default:
                    return null;
            }
        }

        protected SNSAccount _account;

        protected MappingFactoryBase(SNSAccount account)
        {
            _account = account;
            RegisterMapping();
        }

        protected IDictionary<string, IMapping> _mappings = new Dictionary<string, IMapping>();

        public virtual IMapping<T1, T2> GetMapping<T1, T2>()
        {
            var key = typeof(T1).Name +"|"+ typeof(T2).Name;
            if (_mappings.ContainsKey(key))
                return _mappings[key] as IMapping<T1, T2>;
            else
                throw new Exception("Type not register yet");
        }

        public virtual IMapping<T1, T2> GetMapping<T1, T2>(string key)
        {
            var keyStr = key+typeof(T1).Name + "|" + typeof(T2).Name;
            if (_mappings.ContainsKey(keyStr))
                return _mappings[keyStr] as IMapping<T1, T2>;
            else
                throw new Exception("Type not register yet");
        }

        protected abstract void RegisterMapping();

        public SNSAccount Account
        {
            get { return _account; }
        }
    }
}
